<?php

namespace search\controllers\bigdata;

use business\elasticsearch\services\BigDataRadarService;

class RadarController extends BaseController
{
    public $enableCsrfValidation = false;//csrf安全

    /**
     *
     * @api {get} /bigdata/radar/get-list 线索雷达推荐数据
     *
     * @apiVersion 1.0.0
     * @apiGroup bigdataDeveloper
     *
     * @apiDescription 项目订阅
     *
     * @apiParam {Number} page                      页码
     * @apiParam {Number} pageSize                  分页size
     *
     * @apiSuccess {Boolean} success                    返回状态
     * @apiSuccess {String}  message                    返回消息内容
     * @apiSuccess {Number}  errorCode                  错误码
     * @apiSuccess {Object}  data                       对象数组
     */
    public function actionGetList()
    {

        try {

            $areaCodes = $this->getParam('area_code') ?: [];//地区，省市混查
            $bidKeywords = $this->getParam('bid_keyword') ?: [];//招标关键字
            $winBidKeywords = $this->getParam('winbid_keyword') ?: [];//中标关键字
            $excludeKeywords = $this->getParam('exclude_keyword') ?: [];//招/中标排除关键字
            $isLandOpen = $this->getParam('is_land_open');//是否订阅拿地
            $isBuildingOpen = $this->getParam('is_building_open');//是否订阅在建
            $isSaleOpen = $this->getParam('is_sale_open');//是否订阅开盘
            $landUsageLabels = $this->getParam('land_usage_label') ?: [];//土地类型
            $saleTypes = $this->getParam('sale_type') ?: [];//在售类型
            $buildingTypes = $this->getParam('building_type') ?: [];//工程用途
            $projectKeywords = $this->getParam('project_keyword') ?: [];//项目关键字
            $startTime = $this->getParam('start_time');
            $endTime = $this->getParam('end_time');
            $dataType = $this->getParam('data_type');//数据类型 多选
            $page = $this->getParam('page');
            $pageSize = $this->getParam('page_size');
            $page = intval($page) > 0 ? intval($page) : 1;
            $pageSize = intval($pageSize) > 0 ? intval($pageSize) : 100;

            $bigDataRadarService = new BigDataRadarService();
            $rs = $bigDataRadarService->subscript(
                $areaCodes,
                $bidKeywords,
                $winBidKeywords,
                $excludeKeywords,
                $isLandOpen,
                $isBuildingOpen,
                $isSaleOpen,
                $landUsageLabels,
                $saleTypes,
                $buildingTypes,
                $projectKeywords,
                $startTime,
                $endTime,
                $dataType,
                $page,
                $pageSize
            );
            return $this->success($rs);

        } catch (\Exception $ex) {
            \Yii::error($ex);
            return $this->error('', '获取失败，请稍后重试');
        }
    }
}
